home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / propdlg / shapeobj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  2.9 KB  |  135 lines

  1. // shapeobj.cpp
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "propdlg.h"
  15.  
  16. #include "shapeobj.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. IMPLEMENT_SERIAL(CShape, CObject, 0)
  24.  
  25. CShape::CShape()
  26. {
  27.     m_shapecolor = black;
  28.     m_shapestyle = rectangle;
  29.     m_rect = CRect(0,0,0,0);
  30. }
  31.  
  32. CShape::CShape(SHAPE_COLOR_ENUM colorenum, SHAPE_STYLE shapestyle,
  33.     CRect& rect)
  34.     : m_shapestyle(shapestyle), m_rect(rect)
  35. {
  36.     m_shapecolor.e = colorenum;
  37. }
  38.  
  39. void CShape::Draw(CDC* pDC, BOOL bSelected)
  40. {
  41.     CPen* pPenOld = NULL;
  42.     CPen penNew;
  43.     if (bSelected)
  44.     {
  45.         penNew.CreatePen(PS_DASH, 1, RGB(0,0,0));
  46.         pPenOld = pDC->SelectObject(&penNew);
  47.     }
  48.  
  49.     CBrush brushNew((COLORREF)m_shapecolor);
  50.     CBrush* pBrushOld = pDC->SelectObject(&brushNew);
  51.     switch (m_shapestyle)
  52.     {
  53.         case rectangle:
  54.             pDC->Rectangle(m_rect);
  55.             break;
  56.         case rounded_rectangle:
  57.             pDC->RoundRect(m_rect,
  58.                 CPoint(m_rect.Width()/8, m_rect.Height()/8));
  59.             break;
  60.         case ellipse:
  61.             pDC->Ellipse(m_rect);
  62.             break;
  63.     }
  64.  
  65.     pDC->SelectObject(pBrushOld);
  66.     if (pPenOld != NULL)
  67.         pDC->SelectObject(pPenOld);
  68. }
  69.  
  70. void CShape::Serialize(CArchive& ar)
  71. {
  72.     if (ar.IsStoring())
  73.     {
  74.         ar << (WORD)m_shapecolor.e;
  75.         ar << (WORD)m_shapestyle;
  76.         ar << m_rect;
  77.     }
  78.     else
  79.     {
  80.         WORD n;
  81.         ar >> n;
  82.         m_shapecolor.e = (SHAPE_COLOR_ENUM)n;
  83.         ar >> n;
  84.         m_shapestyle = (SHAPE_STYLE)n;
  85.         ar >> m_rect;
  86.     }
  87. }
  88.  
  89.  
  90. SHAPE_COLOR::operator COLORREF() const
  91. {
  92.     switch (e)
  93.     {
  94.         case black: return RGB(0,0,0);
  95. #if _WIN32_WCE < 101 && !defined(_WIN32_WCE_EMULATION)
  96.         //Note: For os 100 & 101, color handled differently on an HPC    
  97.         case dark_gray: return RGB(1,1,1);
  98.         case light_gray: return RGB(2,2,2);
  99. #else
  100.         case dark_gray: return RGB(128,128,128);
  101.         case light_gray: return RGB(192,192,192);
  102. #endif
  103.         case white: return RGB(255,255,255);
  104.     }
  105.     ASSERT(FALSE);
  106.     return 0;
  107. }
  108.  
  109. const SHAPE_COLOR& SHAPE_COLOR::operator = (COLORREF colorref)
  110. {
  111.     switch (colorref)
  112.     {
  113.         case RGB(0,0,0): e = black; break;
  114.         case RGB(1,1,1): e =  dark_gray; break;        //for os 100 & 101 HPCs
  115.         case RGB(2,2,2): e = light_gray; break;        //see note above
  116.         case RGB(128,128,128): e =  dark_gray; break;
  117.         case RGB(192,192,192): e = light_gray; break;
  118.         case RGB(255,255,255): e = white; break;
  119.     }
  120.     ASSERT(FALSE);
  121.     e = black;
  122.     return *this;
  123. }
  124.  
  125. SHAPE_COLOR::operator int() const
  126. {
  127.     return (int)e;
  128. };
  129.  
  130. const SHAPE_COLOR& SHAPE_COLOR::operator = (int n)
  131. {
  132.     e = (SHAPE_COLOR_ENUM)n;
  133.     return *this;
  134. };
  135.